package com.scqkxx.gamebox.activity.myself.adapter;

import android.content.ContentValues;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.avos.avoscloud.AVObject;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.scqkxx.gamebox.R;
import com.scqkxx.gamebox.activity.activities.utils.ActivityUtil;
import com.scqkxx.gamebox.activity.activities.utils.GlideUtils;
import com.scqkxx.gamebox.activity.myself.MyselfEditNicknameActivity;
import com.scqkxx.gamebox.activity.myself.MyselfInforActivity;
import com.scqkxx.gamebox.activity.myself.address.SpaceBean;

import java.util.List;

/**
 * 空间adaper
 */
public class SpaceAdapter extends BaseQuickAdapter<SpaceBean,BaseViewHolder> {

    public SpaceAdapter(int layoutResId, List<SpaceBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SpaceBean item) {
        if (item.getType() == 0){
            GlideUtils.setImageeCircle(mContext,item.getImageUrl(),helper.getView(R.id.spacerImage));
            ((RelativeLayout)helper.getView(R.id.content)).setVisibility(View.VISIBLE);
            ((ImageView)helper.getView(R.id.spacerImage)).setScaleType(ImageView.ScaleType.CENTER_CROP);
            helper.getView(R.id.zhezao).setVisibility(View.VISIBLE);
            ((TextView)helper.getView(R.id.name)).setText("#"+item.getName());
            ((TextView)helper.getView(R.id.tv_position)).setText(item.getPositionNum()+"个位置");
            ((TextView)helper.getView(R.id.tv_menbers)).setText(item.getMembersNum()+"");
            ((TextView)helper.getView(R.id.tv_goods)).setText(item.getGoodsNum()+"个物品");
        } else {
            ((ImageView)helper.getView(R.id.spacerImage)).setImageResource(R.mipmap.edit_icon);
            ((ImageView)helper.getView(R.id.spacerImage)).setScaleType(ImageView.ScaleType.CENTER);
            ((RelativeLayout)helper.getView(R.id.content)).setVisibility(View.GONE);
            helper.getView(R.id.zhezao).setVisibility(View.GONE);
        }
        helper.getView(R.id.spacer).setOnClickListener(v -> {
            ContentValues contentValues = new ContentValues();
            contentValues.put("spaceState" ,1);
            if (item.getType() == 0){
                contentValues.put("belongGroupId" ,item.getBelongGroupId() );
                contentValues.put("objectId" ,item.getObjectId() );
                contentValues.put("spaceId" ,item.getSpaceId() );
                ActivityUtil.switchTo(mContext ,MyselfEditNicknameActivity.class ,contentValues);
            }else{
                //创建一个空间
                contentValues.put("belongGroupId" , item.getBelongGroupId());
                ActivityUtil.switchTo(mContext ,MyselfInforActivity.class ,contentValues);
            }
        });

    }
}
